import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:sk_base/sk_base.dart';
import 'package:sk_base_example/app.dart';
import 'package:sk_base_example/router/test_router.dart';

/**
 *
 * @ProjectName:    sk_base
 * @Package:        example.lib
 * @ClassName:      test
 * @Description:    dart文件作用
 * @Author:         孙浩
 * @CreateDate:     5/22/21 3:16 PM
 */

class Test extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _MyAppState();
}

class _MyAppState extends SKBaseState<Test> {
  @override
  void initState() {
    super.initState();
    //模拟加载
    beginLoading();
    Future.delayed(Duration(seconds: 2), () {
      //模拟加载失败
      loadingComplete();
    });
  }

  @override
  Widget buildView(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(pageTitle),
      ),
      body: Center(
        child: FlatButton(
          child: Text("显示页面"),
          onPressed: () {
            // showDialog(context: context, builder: (ctx) => Container());
            // Navigator.pushNamed(context, TestRouter.Test2Page,arguments: {
            //   "key":"name",
            //   "value":"1"
            // });
            AppStaticData.fluroRouter.navigateTo(
                context, "${TestRouter.Test2Page}",
                routeSettings: RouteSettings(arguments: {
                  "key":"word",
                  "value":1
                }));
          },
        ),
      ),
    );
  }

  @override
  String setPageTitle() => "首页";

  @override
  Widget buildError(BuildContext context) {
    //构建错误样式
    return EasyStateView(
        child: Center(
          child: FlatButton(
              onPressed: () {
                //点击重新加载
                beginLoading();
                Future.delayed(Duration(seconds: 2), () {
                  //加载成功
                  loadingComplete();
                });
              },
              child: Text("重新加载")),
        ),
        title: pageTitle);
  }
}
